<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <base href="${APP_PATH}/">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
    <title>教学管理系统</title>
    <link rel="icon" href="public/favicon.ico" type="image/ico">
    <%@include file="/commons.jsp" %>
</head>

<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <%@ include file="/menu.jsp" %>
        <!--End 左侧导航-->
        <!--头部信息-->
        <%@ include file="/head.jsp" %>
        <!--End 头部信息-->
        <!--页面主要内容-->
        <main class="lyear-layout-content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-toolbar clearfix">
                                <div class="toolbar-btn-action">
                                </div>
                            </div>
                            <div class="card-body">
                                <table class="table  table-bordered">
                                    <thead>
                                    <tr>
                                        <th width="150">序号</th>
                                        <th>备份日期</th>
                                        <th width="300">操作</th>
                                    </tr>
                                    </thead>
                                    <tbody id="data">
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
        <!--End 页面主要内容-->
    </div>
</div>
<script type="text/javascript">
    $(function () {
        layer.msg("加载中", {time: 200, icon: 16, shift: 5}, function () {
            $.ajax({
                url: "manage/data/indexDo",
                type: "post",
                success: function (obj) {
                    if (obj.result) {
                        let listHtml = template("listTpl", {
                            dbList: obj.dbList
                        });
                        $("#data").html(listHtml);
                    } else {
                        layer.msg("刷新失败", {time: 1000, icon: 5, shift: 6}, function () {
                        })
                    }
                }
            })
        });//layer
    });//入口

    function recover(name) {
        if (confirm("确认恢复到" + name + "吗？")) {
            $.ajax({
                url: "manage/data/recover?name=" + name,
                type: "post",
                success: function (obj) {
                    if (obj.result) {
                        layer.msg("恢复数据成功", {time: 1000, icon: 6, shift: 6}, function () {
                            location.href = "login.jsp";
                        })
                    } else {
                        layer.msg("恢复数据失败", {time: 1000, icon: 5, shift: 6}, function () {
                        })
                    }
                }
            })
        }
    }

</script>
</body>
</html>
<script id="listTpl" type="text/html">
    {{each dbList db index}}
    <tr>
        <td>{{index+1}}</td>
        <td>{{db.name}}</td>
        <td>
            <a class="btn btn-primary m-r-5" href="manage/data/download?name={{db.name}}"><i class="mdi mdi-plus"></i>导出</a>
            <a class="btn btn-danger m-r-5" onclick="recover('{{db.name}}')"><i class="mdi mdi-plus"></i>恢复</a>
        </td>
    </tr>
    {{/each}}
</script>
